package com.tools.scanner

import android.app.Activity
import androidx.fragment.app.Fragment
import com.tools.scanner.ui.dialog.LoadingDialog

abstract class BaseFragment : Fragment() {

    private lateinit var mLoadingDialog: LoadingDialog

    fun showLoadingDialog() {
        activity?.let {
            if (it.isDestroyed || it.isFinishing) {
                return
            }

            if (!this::mLoadingDialog.isInitialized) {
                mLoadingDialog = LoadingDialog(it)
            }

            if (mLoadingDialog.isShowing) {
                return
            }

            mLoadingDialog.show()
        }
    }

    fun hideLoadingDialog() {
        if (!this::mLoadingDialog.isInitialized) {
            return
        }

        if (mLoadingDialog.isShowing) {
            mLoadingDialog.dismiss()
        }
    }
}